﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using log4net;

namespace Vroom.Test
{
    [TestClass()]
    public class SqlLocalDbTest
    {
        private static readonly ILog logger = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        [TestMethod()]
        public void usp_VROOM_LOG_InsertTest()
        {
            using (var conn = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=Config;Integrated Security=True;"))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("usp_VROOM_LOG_Insert", conn))
                { 
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@DateTime"  , SqlDbType.DateTime).Value = DateTime.UtcNow;
                    cmd.Parameters.Add("@ExecGuid"  , SqlDbType.VarChar).Value  = Guid.NewGuid().ToString();
                    cmd.Parameters.Add("@ClassGuid" , SqlDbType.VarChar).Value  = Guid.NewGuid().ToString();
                    cmd.Parameters.Add("@Thread"    , SqlDbType.VarChar).Value  = "THREAD";
                    cmd.Parameters.Add("@Level"     , SqlDbType.VarChar).Value  = "LEVEL";
                    cmd.Parameters.Add("@Logger"    , SqlDbType.VarChar).Value  = "LOGGER";
                    cmd.Parameters.Add("@Message"   , SqlDbType.VarChar).Value  = "MESS";
                    cmd.Parameters.Add("@Exception" , SqlDbType.VarChar).Value  = "EXC";
                    int rows = cmd.ExecuteNonQuery();
                }
            }
        }


        [TestMethod()]
        public void Log4NetLogTest()
        {
            log4net.ThreadContext.Properties["ExecGuid"]  = Guid.NewGuid().ToString();
            log4net.ThreadContext.Properties["ClassGuid"] = Guid.NewGuid().ToString();
            logger.Info("TEST LOGGER...");
        }
    }

}
